package com.asiainfo.service;

/*
 * 
 * 会员管理service
 */
import java.util.Date;
import java.util.logging.Logger;

import com.asiainfo.bean.VIP;
import com.asiainfo.dao.Vip_Dao;

public class VipService {
	// 新增会员
	public void addVip(String[] args) {
		Logger logger = Logger.getLogger("");
		if (args.length != 4) {
			logger.warning("对不起，请输入合法参数");
			System.out.println("对不起，请输入合法参数");
			return;
		}
		Vip_Dao vip_dao = new Vip_Dao();
		VIP vip = new VIP(args[1], args[2], args[3], (int) new Date().getTime());
		int newid = vip_dao.add(vip);
		if (newid > 0) {
			vip = vip_dao.findByName(args[1]);
			if (vip != null) {
				System.out.println("OK," + args[1] + "'s member id is " + vip.getId());
			}
		} else if (newid == -1) {
			logger.warning("对不起,用户名" + args[1] + "已存在");
			System.out.println("对不起,用户名" + args[1] + "已存在");
		} else {
			logger.warning("对不起，用户添加失败");
			System.out.println("对不起，用户添加失败");
		}
	}

	// 根据姓名查找会员
	public VIP findVipByName(String name) {
		Vip_Dao vip_dao = new Vip_Dao();
		VIP vip = vip_dao.findByName(name);
		return vip;
	}
}
